using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using MAPDavy.Entities;

namespace MAPDavy.Repository.Mapping
{
	public class TermMap : EntityTypeConfiguration<Term>
	{
		public TermMap()
		{
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.NameTerm)
                .IsRequired()
                .HasMaxLength(100);

            this.Property(t => t.Description)
                .HasMaxLength(250);

            this.Property(t => t.Anio)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(4);

            this.Property(t => t.Color)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("Term");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.NameTerm).HasColumnName("NameTerm");
            this.Property(t => t.Description).HasColumnName("Description");
            this.Property(t => t.Anio).HasColumnName("Anio");
            this.Property(t => t.Cerrado).HasColumnName("Cerrado");
            this.Property(t => t.Color).HasColumnName("Color");
            this.Property(t => t.FechaAplicacion).HasColumnName("FechaAplicacion");
            this.Property(t => t.TestingStartDate).HasColumnName("TestingStartDate");
            this.Property(t => t.TestingEndDate).HasColumnName("TestingEndDate");
            this.Property(t => t.MapId).HasColumnName("MapId");

            // Relationships
            this.HasRequired(t => t.AnioLectivo)
                .WithMany(t => t.Terms)
                .HasForeignKey(d => d.Anio);

            this.HasOptional(t => t.MAP)
                .WithMany(t => t.Terms)
                .HasForeignKey(d => d.MapId);
		}
	}
}

